package com.youku.plugins.commonui.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.events.PlayerControlEvent;
   import com.youku.events.ConductorEvent;
   
   public class BackgroundMediator extends Object
   {
      
      public function BackgroundMediator(param1:MovieClip, param2:IPlayerProxy) {
         super();
         this._mainMc = param1;
         this._playerProxy = param2;
         this._background = new Background();
         this.init();
      }
      
      private var _mainMc:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _background:Background;
      
      private function init() : void {
         this._playerProxy.addEventListener(PlayerControlEvent.FULLSCREEN_CHANGED,this.onPlayerControlEvents);
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_SIZE_CHANGED,this.onPlayerControlEvents);
         this._playerProxy.addEventListener(PlayerControlEvent.HIDE_BACKGROUND,this.onPlayerControlEvents);
         this._playerProxy.addEventListener(PlayerControlEvent.SHOW_BACKGROUND,this.onPlayerControlEvents);
         this._playerProxy.addEventListener(ConductorEvent.STATE_CHANGED,this.onPlayerStateChanged);
         this.background.x = 0;
         this.background.y = 0;
         this._mainMc.addChild(this.background);
      }
      
      private function onPlayerStateChanged(param1:ConductorEvent) : void {
         var _loc2_:String = param1.data as String;
      }
      
      private function onPlayerControlEvents(param1:PlayerControlEvent) : void {
         var _loc2_:* = NaN;
         var _loc3_:* = NaN;
         switch(param1.type)
         {
            case PlayerControlEvent.FULLSCREEN_CHANGED:
            case PlayerControlEvent.PLAYER_SIZE_CHANGED:
               _loc2_ = param1.data.width;
               _loc3_ = param1.data.height;
               this.background.setSize(_loc2_,_loc3_);
               break;
            case PlayerControlEvent.SHOW_BACKGROUND:
               if(!this._mainMc.contains(this._background))
               {
                  this._mainMc.addChildAt(this.background,0);
               }
               break;
            case PlayerControlEvent.HIDE_BACKGROUND:
               if(this._mainMc.contains(this._background))
               {
                  this._mainMc.removeChild(this.background);
               }
               break;
         }
      }
      
      private function get background() : Background {
         return this._background;
      }
   }
}
